Move color parser from an1 to util.c. Teach Ozi cmd line parser to use it.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 2 Dec 2005 19:14:38 +0000 (19:14 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Fri, 2 Dec 2005 19:14:38 +0000 (19:14 +0000)
gpsbabel/an1.c
gpsbabel/defs.h
gpsbabel/ozi.c
gpsbabel/util.c

index 64cc40740c20030cbe9f34ad67d0290c1a92fa3d..39492218269bb5653e64a11a6a4d2450849e2700 100644 (file)
@@ -1042,87 +1042,6 @@ Init_Road_Changes( void )
        xfree( copy );
 }
 
-int HexDigit( char hex ) {
-       const char *Digits = "0123456789ABCDEF";
-       const char *digits = "0123456789abcdef";
-       char * ofs = strchr( digits, hex );
-       if ( ofs ) {
-               return ofs-digits;
-       }
-       
-       ofs = strchr( Digits, hex );
-       if ( ofs ) {
-               return ofs-Digits;
-       }
-       return 0;
-}
-
-int HexByte( char* hex ) {
-       int b =  (HexDigit(hex[0])<<4)+HexDigit(hex[1]);
-       return b;
-}
-
-void Init_Color( void ) {
-       if ( opt_color[0] == '#' ) {
-               opt_color_num = (HexByte( opt_color+1 )) +    // red
-                               (HexByte( opt_color+3 )<<8) + // green
-                               (HexByte( opt_color+5 )<<16); // blue
-       }
-       else if ( !case_ignore_strcmp( opt_color, "aqua" ) ||
-                 !case_ignore_strcmp( opt_color, "cyan" )) {
-               opt_color_num = 0xffff00;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "black" )) {
-               opt_color_num = 0x000000;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "blue" )) {
-               opt_color_num = 0xff0000;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "fuchsia" ) ||
-                 !case_ignore_strcmp( opt_color, "magenta" )) {
-               opt_color_num = 0xff00ff;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "gray" )) {
-               opt_color_num = 0x808080;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "green" )) {
-               opt_color_num = 0x008000;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "lime" )) {
-               opt_color_num = 0x00ff00;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "maroon" )) {
-               opt_color_num = 0x000080;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "navy" )) {
-               opt_color_num = 0x800000;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "olive" )) {
-               opt_color_num = 0x008080;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "purple" )) {
-               opt_color_num = 0x800080;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "red" )) {
-               opt_color_num = 0x0000ff;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "silver" )) {
-               opt_color_num = 0xc0c0c0;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "teal" )) {
-               opt_color_num = 0x808000;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "white" )) {
-               opt_color_num = 0xffffff;
-       }
-       else if ( !case_ignore_strcmp( opt_color, "yellow" )) {
-               opt_color_num = 0x00ffff;
-       }
-       else {
-               fatal( MYNAME ": unrecognized color name\n" );
-       }
-}
-
 static void
 rd_init(const char *fname)
 {
@@ -1150,7 +1069,7 @@ wr_init(const char *fname)
        outfile = xfopen( fname, "wb", MYNAME );
        Init_Output_Type();
        Init_Road_Changes();
-       Init_Color();
+       opt_color_num = color_to_bbggrr(opt_color);
        Init_Wpt_Type();
        if ( opt_zoom ) {
                opt_zoom_num = atoi(opt_zoom);
index fb3e6c2cc247d92b11cbc8fa2fea752b2048f4a8..ea8a848cffc09ec6222de27b80303faab858ee11 100644 (file)
@@ -683,6 +683,11 @@ double degrees2ddmm(double deg_val);
  */
 unsigned long get_crc32(const void * data, int datalen);
 
+/*
+ * Color helpers.
+ */
+int color_to_bbggrr(char *cname);
+
 /*
  * A constant for unknown altitude.   It's tempting to just use zero
  * but that's not very nice for the folks near sea level.
index af3b94a3d726bee31c2bb6a03717f7dd372660df..8238678f20586fd7f806cb716fcad72a02fadf1f 100644 (file)
@@ -50,6 +50,10 @@ static char *snlenopt = NULL;
 static char *snwhiteopt = NULL;
 static char *snupperopt = NULL;
 static char *snuniqueopt = NULL;
+static char *wptfgcolor = NULL;
+static char *wptbgcolor = NULL;
+
+
 
 static
 arglist_t ozi_args[] = {
@@ -61,6 +65,10 @@ arglist_t ozi_args[] = {
                NULL, ARGTYPE_BOOL},
        {"snunique", &snuniqueopt, "Make synth. shortnames unique",
                NULL, ARGTYPE_BOOL},
+       {"wptfgcolor", &wptfgcolor, "Waypoint foreground color",
+               "black", ARGTYPE_INT},
+       {"wptbgcolor", &wptbgcolor, "Waypoint background color",
+               "yellow", ARGTYPE_INT},
        {0, 0, 0, 0, 0}
 };
 
@@ -92,9 +100,9 @@ ozi_alloc_fsdata(void)
        fsdata->fs.copy = (fs_copy) ozi_copy_fsdata;
        fsdata->fs.destroy = ozi_free_fsdata;
 
-       /* Provide reasonable defaults */
-       fsdata->fgcolor = 0;
-       fsdata->bgcolor = 65535;
+       /* Provide defaults via command line defaults */
+       fsdata->fgcolor = color_to_bbggrr(wptfgcolor);
+       fsdata->bgcolor = color_to_bbggrr(wptbgcolor);
 
        return fsdata;
 }
index fa0438584c7f8274f92fa62e948966ac48dbda45..b3457cd571be86b7dfee5ca6a4b08cb213d655fc 100644 (file)
@@ -1084,3 +1084,108 @@ char *xml_attribute( xml_tag *tag, char *attrname )
        }
        return result;
 }
+
+/*
+ * Functions for converting human-readable colors to BBGGRR value.
+ * Substantial optimization opportunities remain.
+ */
+int HexDigit( char hex ) {
+       const char *Digits = "0123456789ABCDEF";
+       const char *digits = "0123456789abcdef";
+       char * ofs = strchr( digits, hex );
+       if ( ofs ) {
+               return ofs-digits;
+       }
+       
+       ofs = strchr( Digits, hex );
+       if ( ofs ) {
+               return ofs-Digits;
+       }
+       return 0;
+}
+
+int HexByte( char* hex ) {
+       int b =  (HexDigit(hex[0])<<4)+HexDigit(hex[1]);
+       return b;
+}
+
+/*
+ * Given an input of the form:
+ *   #<hex number for RGB value>
+ *   <decimal nummber for BBGGRR value>
+ *   <color named in CSS1 spec>
+ * return the BBGGRR value for it.
+ */
+int
+color_to_bbggrr( char *opt_color ) 
+{
+       int color_num;
+       char *ep;
+       
+       color_num = strtol(opt_color, &ep, 10);
+
+       if (ep != opt_color) {
+               return color_num;
+        } 
+       else if ( opt_color[0] == '#' ) {
+               color_num = (HexByte( opt_color+1 )) +    // red
+                               (HexByte( opt_color+3 )<<8) + // green
+                               (HexByte( opt_color+5 )<<16); // blue
+       }
+       else if ( !case_ignore_strcmp( opt_color, "aqua" ) ||
+                 !case_ignore_strcmp( opt_color, "cyan" )) {
+               color_num = 0xffff00;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "black" )) {
+               color_num = 0x000000;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "blue" )) {
+               color_num = 0xff0000;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "fuchsia" ) ||
+                 !case_ignore_strcmp( opt_color, "magenta" )) {
+               color_num = 0xff00ff;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "gray" )) {
+               color_num = 0x808080;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "green" )) {
+               color_num = 0x008000;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "lime" )) {
+               color_num = 0x00ff00;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "maroon" )) {
+               color_num = 0x000080;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "navy" )) {
+               color_num = 0x800000;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "olive" )) {
+               color_num = 0x008080;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "purple" )) {
+               color_num = 0x800080;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "red" )) {
+               color_num = 0x0000ff;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "silver" )) {
+               color_num = 0xc0c0c0;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "teal" )) {
+               color_num = 0x808000;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "white" )) {
+               color_num = 0xffffff;
+       }
+       else if ( !case_ignore_strcmp( opt_color, "yellow" )) {
+               color_num = 0x00ffff;
+       }
+       else {
+               fatal( "unrecognized color name %s\n", opt_color );
+       }
+
+       return color_num;
+}